package org.huel.backend.domain.dto;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;


/**
 * 出勤统计DTO
 */
@Getter
public class AttendanceStatsDTO {
    // Getter和Setter方法
    @Setter
    private String name; // 名称（学生姓名、课程名、班级名等）
    @Setter
    private String id; // ID（学生ID、课程ID、班级ID等）
    private Long totalCount; // 总记录数
    private Long presentCount; // 出勤次数
    private Long absentCount; // 缺勤次数
    @Setter
    private Double attendanceRate; // 出勤率

    // 构造函数
    public AttendanceStatsDTO() {}

    public AttendanceStatsDTO(String name, String id, Long totalCount, Long presentCount, Long absentCount) {
        this.name = name;
        this.id = id;
        this.totalCount = totalCount;
        this.presentCount = presentCount;
        this.absentCount = absentCount;
        this.calculateAttendanceRate();
    }

    // 计算出勤率
    public void calculateAttendanceRate() {
        if (totalCount != null && totalCount > 0) {
            this.attendanceRate = (presentCount.doubleValue() / totalCount.doubleValue()) * 100.0;
            // 保留2位小数
            this.attendanceRate = Math.round(this.attendanceRate * 100.0) / 100.0;
        } else {
            this.attendanceRate = 0.0;
        }
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
        this.calculateAttendanceRate();
    }

    public void setPresentCount(Long presentCount) {
        this.presentCount = presentCount;
        this.calculateAttendanceRate();
    }

    public void setAbsentCount(Long absentCount) {
        this.absentCount = absentCount;
        this.calculateAttendanceRate();
    }

    @Override
    public String toString() {
        return "AttendanceStatsDTO{" +
                "name='" + name + '\'' +
                ", id='" + id + '\'' +
                ", totalCount=" + totalCount +
                ", presentCount=" + presentCount +
                ", absentCount=" + absentCount +
                ", attendanceRate=" + attendanceRate +
                '}';
    }
}